<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form id="addRMPO" binding="#{rawMaterialPurchasingManagerBean.loadAddRMPO}">
                    <p:panel header="Material Requirement Plans" id="materialRequirementPlansPanel">
                        <p:dataTable id="mrPlans" var="mrplans" value="#{rawMaterialPurchasingManagerBean.materialRequirementPlans}"
                                     emptyMessage="No material requirement plans found with given criteria.">          
                            <p:column filterBy="#{mrplans.rawMaterial.name}" headerText="Raw Material Name" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.rawMaterial.name}" />  
                            </p:column> 
                            <p:column filterBy="#{mrplans.weight}" headerText="Required Amount (kg / litre)" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.weight}" />  
                            </p:column>
                            <p:column filterBy="#{mrplans.orderDate}" headerText="Date to Order" filterMatchMode="contains">  
                                <h:outputText value="#{mrplans.orderDate}" >
                                    <f:convertDateTime pattern="dd-MMM-yyyy" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>
                            </p:column>                        
                        </p:dataTable> 
                    </p:panel>
                    <p:panel id="suppliersPanel" header="Suppliers">
                        <p:dataTable id="suppliers" var="supplier" value="#{rawMaterialPurchasingManagerBean.suppliers}" 
                                     selectionMode="single" 
                                     selection="#{rawMaterialPurchasingManagerBean.selectedSupplier}"
                                     emptyMessage="No suppliers found with given criteria.">
                            <p:column filterBy="#{supplier.name}" headerText="Name" filterMatchMode="contains">  
                                <h:outputText value="#{supplier.name}" />  
                            </p:column> 
                            <p:column filterBy="#{supplier.company}" headerText="Company" filterMatchMode="contains">  
                                <h:outputText value="#{supplier.company}" />  
                            </p:column>
                            <p:column filterBy="#{supplier.contact}" headerText="Contact" filterMatchMode="contains">  
                                <h:outputText value="#{supplier.contact}" />  
                            </p:column> 
                            <p:column filterBy="#{supplier.email}" headerText="Email" filterMatchMode="contains">  
                                <h:outputText value="#{supplier.email}" />  
                            </p:column> 
                        </p:dataTable>
                    </p:panel>
                    <p:panel id="orderDetailsPanel" header="Order Details">
                        <p:messages />

                        <table border="0" width="100%">
                            <tr>
                                <td width="200px">Delivery Date:</td>
                                <td>
                                    <p:calendar required="true" requiredMessage="Delivery date is required." 
                                                value="#{rawMaterialPurchasingManagerBean.deliveryDate}" pattern="dd-MM-yyyy" 
                                                title="Date of delivery."/> 
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Amount to Pay:</td>
                                <td>
                                    <p:inputText id="amountToPay" value="#{rawMaterialPurchasingManagerBean.amountToPay}" required="true"
                                                 requiredMessage="Amount to pay is required" label="Amount to Pay"
                                                 title="Amount to pay for the order."> 
                                        <f:convertNumber minFractionDigits="2" /> 
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td>Remarks:</td>
                                <td>
                                    <p:inputTextarea id="remarks" label="Remarks"
                                                     title="Remarks for the order."
                                                     style="width:450px;height:75px;" 
                                                     value="#{rawMaterialPurchasingManagerBean.remark}">
                                    </p:inputTextarea>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <p:commandButton id="btnPlaceOrder" value="Place an Order" 
                                                     title="Place order for raw material." ajax="true"
                                                     update="orderDetailsPanel"
                                                     actionListener="#{rawMaterialPurchasingManagerBean.placeAnOrder}" />  
                                    <p:commandButton id="btnBackFromAddRMPO" value="Back"
                                                     immediate="true" ajax="true"
                                                     title="Go back to the previous page."
                                                     actionListener="#{rawMaterialPurchasingManagerBean.back}"/>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
